/*
 * mounttable.h
 *
 *  Created on: Dec 29, 2008
 *      Author: yospaly
 */

#ifndef MOUNTTABLE_H_
#define MOUNTTABLE_H_

#include <wx/wx.h>
#include <wx/msw/registry.h>


struct MountPoint{
	wxString posix;
	wxString native;
	bool istext;
};
WX_DECLARE_STRING_HASH_MAP(MountPoint, MountPointHash);

class MountTable {
public:
	static MountTable& get() {
		return self;
	}
	
	virtual ~MountTable();
	
	wxString cygpath(const wxString& posix_path);

	void remove(const wxString& posix);
	void remove_all() {
		MountPointHash::iterator it;
		for (it=mount_hash.begin(); it!=mount_hash.end(); it++) {
			remove(it->first);
		}
    }
	
	bool is_cygwin_installed() {
		return _cygwin_installed;
    }
	
    void set_root_dir (const wxString& rootdir=wxEmptyString);

	const wxString get_root_dir() {
		return mount_hash[_T("/")].native;
	}
    void create_install_root();
	
	MountPointHash mount_hash;
	
	enum
	{
	  MOUNT_SYMLINK =       0x001,  /* "mount point" is a symlink */
	  MOUNT_BINARY =        0x002,  /* "binary" format read/writes */
	  MOUNT_SYSTEM =        0x008,  /* mount point came from system table */
	  MOUNT_EXEC   =        0x010,  /* Any file in the mounted directory gets 'x' bit */
	  MOUNT_AUTO   =        0x020,  /* mount point refers to auto device mount */
	  MOUNT_CYGWIN_EXEC =   0x040,  /* file or directory is or contains a cygwin executable */
	  MOUNT_MIXED   =       0x080,  /* reads are text, writes are binary */
	};
	
protected:
    bool _from_fstab(const wxString& in_path);
    bool _from_fstab_line(const wxString& line);
    void _add_usr_mnts();
    void _check_cygwin_installed();

	bool _cygwin_installed;
	
	static MountTable self;

    bool _got_usr_lib;
    bool _got_usr_bin;
	
	MountTable();
};

#endif /* MOUNTTABLE_H_ */
